Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
.innerHTML -> console.log shows formatting but DOM element doesn't
        let parser = new DOMParser();
        let OFPXML = parser.parseFromString(json, "application/xml");
        Formats = OFPXML.querySelector('Formats');
        XML1 = Formats.children[1].innerHTML;
        console.log(XML1); // This retains linebreaks
        document.getElementById('text_from_XML_node_here').innerHTML = XML1;  // This does not retain them.

Console.log shows the text with linebreaks but the DOM element removed them all.

This is a low-priority question as I am just learning and experimenting with things.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The line breaks are not shown in the rendered HTML element. When DOM elements are rendered, raw newlines like \n are ignored. If you want line breaks explicitly to show, you have the following options:

  • Change the element to a <pre>
  • Replace newlines in your XML1 variable with <br />
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!